home *** CD-ROM | disk | FTP | other *** search
/ Floppyshop 2 / Floppyshop - 2.zip / Floppyshop - 2.iso / diskmags / 0022-3.564 / dmg-0089 / picres.txt < prev    next >
Text File  |  1997-04-16  |  31KB  |  725 lines

  1.  
  2.    John Brochu, author of the famed "PicSwitch", sent me a letter
  3. and a disk containing modified picture format descriptions for NeoChrome, 
  4. DEGAS Elite Compressed, Spectrum 512 Compressed, GEM Bit Image, IFF, 
  5. and MacPaint formats.  John also sent a description of the PackBits
  6. compression method used in DEGAS Elite, IFF, and MacPaint formats.
  7.  
  8.    Here's the new version with his corrections.  Many thanks go to
  9. John for his contributions, and also to Gerfried Klein who sent
  10. the MacPaint description as described by by *pple, corp.
  11.  
  12. Dave Baggett
  13. dmb@wam.umd.edu | dmb@TIS.COM
  14.  
  15. PS> The "GEM Bit Image" description in previous versions describes an
  16.     outdated version of this format which has been replaced by what
  17.     is described below.  John believes that the old format was never
  18.     actually implemented, so I took the description out.
  19.  
  20. ----------------------------------- >8 ----------------------------------------
  21.  
  22.                            ST Picture Formats
  23.                            ------------------
  24.                                Edited by:
  25.  
  26.                               David Baggett
  27.                          5640 Vantage Point Road
  28.                          Columbia, MD  21044 USA
  29.                              (301)  596-4779    
  30.                           (usenet: dmb@TIS.COM)
  31.  
  32.                    (Please report errors or additions)
  33.  
  34.            Copyright (C) 1988, 1989, 1990 by David M. Baggett
  35.  
  36.  
  37.     Non-profit redistribution of this document is permitted, provided
  38.     the document is not modified in any way.
  39.  
  40.     Reproduction of this document in whole or in part for  commercial
  41.     purposes is expressly forbidden without the prior written consent
  42.     of David M. Baggett.
  43.  
  44.     The  information  presented here is not guaranteed to be correct.
  45.     The editor and contributors will in no event be liable for direct,
  46.     indirect, incidental, or consequential damages resulting from the 
  47.     use of the information in this document.
  48.  
  49.     This document is the product of many hours of volunteer work by a
  50.     large number of people. Please respect this -- do not violate the
  51.     distribution policy.
  52.  
  53.  
  54.                               CONTRIBUTORS
  55.   
  56.             Phil Blanchfield  Jason Blochowiak John Brochu**
  57.         David Brooks  Neil Forsyth  Stefan Hoehn  Gerfried Klein
  58.           Ken MacLeod  Jim McCabe  Darek Mihocka  David Mumper
  59.     George Seto Joe Smith  Greg Wageman  Roland Waldi* Gerry Wheeler
  60.  
  61.  
  62.                                 Contents 
  63.                                 --------
  64.  
  65.         NEOchrome                               *.NEO
  66.         NEOchrome Animation                     *.ANI
  67.         DEGAS                                   *.PI?   ? = 1, 2, 3
  68.         DEGAS Elite                             *.PI?   ? = 1, 2, 3
  69.         DEGAS Elite (Compressed)                *.PC?   ? = 1, 2, 3
  70.         Tiny                                    *.TN?   ? = 1, 2, 3, Y
  71.         Spectrum 512                            *.SPU
  72.         Spectrum 512 (Compressed)               *.SPC
  73.         Art Director                            *.ART
  74.         C.O.L.R. Object Editor Mural            *.MUR
  75.         Doodle                                  *.DOO
  76.         Animatic Film                           *.FLM
  77.         GEM Bit Image                           *.IMG
  78.         STAD                                    *.PAC
  79.         Imagic Film/Picture                     *.IC?   ? = 1, 2, 3
  80.         IFF                                     *.IFF
  81.         MacPaint                                *.MAC
  82.         PackBits Compression Algorithm
  83.  
  84.  
  85.                         Introductory Information
  86.                         ------------------------
  87. word    = 2 bytes
  88. long    = 4 bytes
  89. palette = Hardware color palette, stored as 16 words.  First word is
  90.           color register zero (background), last word is color register
  91.           15.  Each word has the form:
  92.  
  93.           Bit:  (MSB) 15 14 13 12 11 10 09 08 07 06 05 04 03 02 01 00 (LSB)
  94.                       -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
  95.                        0  0  0  0  0 R2 R1 R0  0 G2 G1 G0  0 B2 B1 B0
  96.  
  97.           R2 = MSB of red intensity
  98.           R0 = LSB of red intensity
  99.  
  100.           G2 = MSB of green intensity
  101.           G0 = LSB of green intensity
  102.  
  103.           B2 = MSB of blue intensity
  104.           B0 = LSB of blue intensity
  105.  
  106.           Intensity ranges from 0 (color not present) to 7 (highest
  107.           intensity).
  108.  
  109.           Example: { red = 7, green = 3, blue = 5 } -> 0735 (hex)
  110.  
  111.           Caveat:  It is wise to mask off the upper four bits of each
  112.                    palette entry, since a few programs store special
  113.                    information there (most notably Art Studio).
  114.  
  115.  
  116.                              The Formats
  117.                              -----------
  118.  
  119. <NEOchrome>     *.NEO
  120.  
  121. 1 word          flag byte [always 0]
  122. 1 word          resolution [0 = low res, 1 = medium res, 2 = high res]
  123. 16 words        palette
  124. 12 bytes        filename [usually "        .   "]
  125. 1 word          color animation limits.  High bit (bit 15) set if color
  126.                 animation data is valid.  Low byte contains color animation
  127.                 limits (4 most significant bits are left/lower limit,
  128.                 4 least significant bits are right/upper limit).
  129. 1 word          color animation speed and direction.  High bit (bit 15) set
  130.                 if animation is on.  Low order byte is # vblanks per step.
  131.                 If negative, scroll is left (decreasing).  Number of vblanks
  132.                 between cycles is |x| - 1
  133. 1 word          # of color steps (as defined in previous word) to display
  134.                 picture before going to the next.  (For use in slide shows)
  135. 1 word          image X offset [unused, always 0]
  136. 1 word          image Y offset [unused, always 0]
  137. 1 word          image width [unused, always 320]
  138. 1 word          image height [unused, always 200]
  139. 33 words        reserved for future expansion
  140. 16000 words     picture data (screen memory)
  141. -----------
  142. 32128 bytes     total
  143.  
  144.  
  145. <NEOchrome Animation>        *.ANI
  146.  
  147. NOTE:      To get this feature on versions 0.9 and later select the Grabber
  148.         icon and click both mouse buttons in the eye of the second R in the
  149.         word GRABBER.
  150.            Interestingly enough, some versions of NEO only require you
  151.         to press the right button, not both.  Hmmm...
  152.  
  153. 1 long          magic number BABEEBEA (hex) (seems to be ignored)
  154. 1 word          width of image in bytes (always divisible by 8)
  155. 1 word          height of image in scan lines
  156. 1 word          size of image in bytes + 10 (!)
  157. 1 word          x coordinate of image (must be divisible by 16) - 1
  158. 1 word          y coordinate of image - 1
  159. 1 word          number of frames
  160. 1 word          animation speed (# vblanks to delay between frames)
  161. 1 long          reserved; should be zero
  162. --------
  163. 22 bytes        total for header
  164.  
  165. ? words         image data (words of screen memory) for each frame, in 
  166.                 order
  167.  
  168.  
  169. <DEGAS>         *.PI1 (low resolution)
  170.                 *.PI2 (medium resolution)
  171.                 *.PI3 (high resolution)
  172.  
  173. 1 word          resolution (0 = low res, 1 = medium res, 2 = high res)
  174.                 Other bits may be used in the future; use a simple bit
  175.                 test rather than checking for specific word values.
  176. 16 words        palette
  177. 16000 words     picture data (screen memory)
  178. -----------
  179. 32034 bytes     total
  180.  
  181.  
  182. <DEGAS Elite>   *.PI1 (low resolution)
  183.                 *.PI2 (medium resolution)
  184.                 *.PI3 (high resolution)
  185.  
  186. 1 word          resolution (0 = low res, 1 = medium res, 2 = high res)
  187.                 Other bits may be used in the future; use a simple bit
  188.                 test rather than checking for specific word values.
  189. 16 words        palette
  190. 16000 words     picture data (screen memory)
  191. 4 words         left color animtion limit table (starting color numbers)
  192. 4 words         right color animation limit table (ending color numbers)
  193. 4 words         animation channel direction flag (0 = left, 1 = off, 2 = right)
  194. 4 words         128 - animation channel delay in 1/60's of a second. [0 - 128]
  195.                 (I.e., subtract word from 128 to get 1/60th's of a second.)
  196. -----------
  197. 32066 bytes     total
  198.  
  199.  
  200. <DEGAS Elite (Compressed)>      *.PC1 (low resolution)
  201.                                 *.PC2 (medium resolution)
  202.                                 *.PC3 (high resolution)
  203.  
  204. 1 word          resolution (same as Degas, but high order bit is set;
  205.                 i.e., hex 8000 = low res, hex 8001 = medium res,
  206.                 hex 8002 = high res).  Other bits may be used in the
  207.                 future; use a simple bit test rather than checking
  208.                 for specific word values.
  209. 16 words        palette
  210. < 32000 bytes   control/data bytes
  211. 4 words         left color animation limit table (starting color numbers)
  212. 4 words         right color animation limit table (ending color numbers)
  213. 4 words         animation channel direction flag [0 = left, 1 = off, 2 = right]
  214. 4 words         128 - animation channel delay in 1/60's of a second. [0 - 128]
  215.                 (I.e., subtract word from 128 to get 1/60th's of a second.)
  216. -----------
  217. < 32066 bytes   total
  218.  
  219. Compression Scheme:
  220.  
  221.    PackBits compression is used (see below).  Each scan line is compressed
  222. separately; i.e., all data for a given scan line appears before any data
  223. for the next scan line.  The scan lines are specified from top to bottom
  224. (i.e., 0 is first).  For each scan line, all the data for a given bit plane
  225. appears before any data for the next higher order bit plane.  Note this is
  226. identical to the IFF 'BODY' image data.
  227.    To clarify:  The first data in the file will be the data for the lowest
  228. order bit plane of scan line zero, followed by the data for the next higher
  229. order bit plane of scan line zero, etc., until all bit planes have been
  230. specified for scan line zero.  The next data in the file will be the data
  231. for the lowest order bit plane of scan line one, followed by the data for
  232. the next higher order bit plane of scan line one, etc., until all bit planes
  233. have been specified for all scan lines.
  234.  
  235. Caveats:
  236.  
  237.    DEGAS Elite's picture loading routine places some restrictions on
  238. compressed DEGAS files:
  239.  
  240.         o Elite uses a 40-byte buffer to store data being decompressed.
  241.  
  242.         o Whenever a control command is encountered, bytes are stuffed
  243.         in this buffer.
  244.  
  245.         o The buffer is only emptied when there are EXACTLY 40
  246.         characters in it.
  247.  
  248. The important conclusion here is that
  249.  
  250.         No control command may cause the buffer to have more than 40
  251.         bytes in it.  In other words, all control commands must end on
  252.         or before the 40-byte boundary.
  253.  
  254. Any picture violating the last condition will cause Elite to get a bus
  255. error when the picture is loaded.
  256.  
  257.  
  258. <Tiny>  *.TNY (any resolution)
  259.         *.TN1 (low resolution)
  260.         *.TN2 (medium resolution)
  261.         *.TN3 (high resolution)
  262.  
  263.    Several people have reported sightings of mutated Tiny pictures that
  264. do not follow the standard format, so let's be careful out there.  What
  265. is described here is the format that David Mumper's original
  266. TNYSTUFF.PRG produces.
  267.  
  268. 1 byte          resolution (same as NEO, but +3 indicates rotation
  269.                 information also follows)
  270.  
  271. If resolution > 2 {
  272. 1 byte          left and right color animation limits.  High 4 bits
  273.                 hold left (start) limit; low 4 bits hold right (end)
  274.                 limit
  275. 1 byte          direction and speed of color animation (negative value
  276.                 indicates left, positive indicates right, absolute value
  277.                 is delay in 1/60's of a second.
  278. 1 word          color rotation duration (number of iterations)
  279. }
  280.  
  281. 16 words        palette
  282. 1 word          number of control bytes
  283. 1 word          number of data words
  284. 3-10667 bytes   control bytes
  285. 1-16000 words   data words
  286. -------------
  287. 42-32044 bytes  total
  288.  
  289. Control byte meanings:
  290.  
  291.         For a given control byte, x:
  292.  
  293.         x < 0   Absolute value specifies the number of unique words to
  294.                 take from the data section (from 1 to 127)
  295.         x = 0   1 word is taken from the control section which specifies
  296.                 the number of times to repeat the next data word (from
  297.                 128 to 32767)
  298.         x = 1   1 word is taken from the control section which specifies
  299.                 the number of unique words to be taken from the data
  300.                 section (from 128 - 32767)
  301.         x > 1   Specifies the number of times to repeat the next word
  302.                 taken from the data section (from 2 to 127)
  303.  
  304. Format of expanded data:
  305.  
  306.    The expanded data is not simply screen memory bitmap data; instead, the 
  307. data is divided into four sets of vertical columns.  (This results in
  308. better compression.)  A column consists of one specific word taken
  309. from each scan line, going from top to bottom.  For example, column 1 
  310. consists of word 1 on scanline 1 followed by word 1 on scanline 2, etc., 
  311. followed by word 1 on scanline 200.
  312.    The columns appear in the following order:
  313.  
  314.    1st set contains columns 1, 5,  9, 13, ..., 69, 73, 77 in order
  315.    2nd set contains columns 2, 6, 10, 14, ..., 70, 74, 78 in order
  316.    3rd set contains columns 3, 7, 11, 15, ..., 71, 75, 79 in order
  317.    4th set contains columns 4, 8, 12, 16, ..., 72, 76, 80 in order
  318.  
  319. Note that Tiny partitions the screen this way regardless of resolution; i.e., 
  320. these aren't bitplanes.  For example, medium resoltion only has two bitplanes, 
  321. but Tiny still divides medium resolution pictures into four parts.
  322.  
  323.  
  324. <Spectrum 512>  *.SPU
  325.  
  326. 80 words        first scan line of picture (unused) -- should be zeroes
  327. 15920 words     picture data (screen memory) for scan lines 1 through 199
  328. 9552 words      3 palettes for each scan line (the top scan line is
  329.                 not included because Spectrum 512 can't display it)
  330. -----------
  331. 51104 bytes     total
  332.  
  333.  
  334. <Spectrum 512 (Compressed)>        *.SPC
  335.  
  336. 1 word          flag word [$5350 or "SP"]
  337. 1 word          reserved for future use [always 0]
  338. 1 long          length of data bit map
  339. 1 long          length of color bit map
  340. <= 32092 bytes  compressed data bit map
  341. <= 17910 bytes  compressed color bit map
  342. --------------
  343. <= 50014 bytes   total
  344.  
  345. Data compression:
  346.  
  347.    Compression is via a modified run length encoding (RLE) scheme,
  348. similar to DEGAS compressed and Tiny.  The data map is stored as a
  349. sequence of records.  Each record consists of a header byte followed by
  350. one or more data bytes.  The meaning of the header byte is as follows:
  351.  
  352.         For a given header byte, x:
  353.  
  354.            0 <= x <= 127   Use the next x + 1 bytes literally (no repetition)
  355.         -128 <= x <=  -1   Use the next byte -x + 2 times
  356.  
  357. The data appears in the following order:
  358.  
  359.         1. Picture data, bit plane 0, scan lines 1 - 199
  360.         2. Picture data, bit plane 1, scan lines 1 - 199
  361.         3. Picture data, bit plane 2, scan lines 1 - 199
  362.         4. Picture data, bit plane 3, scan lines 1 - 199
  363.  
  364. Decompression of data ends when 31840 data bytes have been used.
  365.  
  366. Color map compression:
  367.  
  368.    Each 16-word palette is compressed separately.  There are three
  369. palettes for each scan line (597 total).  The color map is stored as a
  370. sequence of records.  Each record starts with a 1-word bit vector which
  371. specifies which of the 16 palette entries are included in the data
  372. following the bit vector (1 = included, 0 = not included).  If a palette
  373. entry is not included, it is assumed to be zero (black).  The least
  374. significant bit of the bit vector refers to palette entry zero, while the
  375. most significant bit refers to palette entry 15.  Bit 15 must be zero,
  376. since Spectrum 512 does not use palette entry 15.  Bit 0 should also be
  377. zero, since Spectrum 512 always makes the background color black.
  378.    The words specifying the values for the palette entries indicated in
  379. the bit vector follow the bit vector itself, in order (0 - 15).
  380.  
  381.  
  382. <Art Director>  *.ART (low resolution only)
  383.  
  384. 16000 words     picture data (screen memory)
  385. 16 words        palette
  386. 15 * 16 words   15 more palettes for animation
  387. -------------
  388. 32512 bytes     total
  389.  
  390.  
  391. <C.O.L.R. Object Editor Mural>        *.MUR (low resolution only)
  392.  
  393. 16000 words     picture data (screen memory)
  394.                 (palettes are stored in separate files)
  395. -----------
  396. 32000 bytes     total
  397.  
  398.  
  399. <Doodle>        *.DOO (high resolution only)
  400.  
  401. 16000 words     picture data (screen memory)
  402. -----------
  403. 32000 bytes     total
  404.  
  405.  
  406. <Animatic Film> *.FLM (low resolution only)
  407.  
  408. 1 word          number of frames
  409. 16 words        palette
  410. 1 word          speed (0 - 99; value is 99 - # vblanks to delay between frames)
  411. 1 word          direction (0 = forwards, 1 = backwards)
  412. 1 word          end action (what to do after the last frame)
  413.                 0 = pause, then repeat from beginning
  414.                 1 = immediately repeat from beginning
  415.                 2 = reverse (change direction)
  416. 1 word          width of film in pixels
  417. 1 word          height of film in pixels
  418. 1 word          Animatic version number (major)
  419. 1 word          Animatic version number (minor)
  420. 1 long          magic number 27182818 (hex)
  421. 3 longs         reserved for expansion (should be all zeros)
  422. --------
  423. 32 words        total for header
  424.  
  425. ? words         image data (words of screen memory) for each frame, in order
  426.  
  427.  
  428. <GEM Bit Image> *.IMG
  429.  
  430. 1 word          version number of image file [1]
  431. 1 word          length of header in words [usually 8]
  432. 1 word          number of color planes [1 for monochrome]
  433. 1 word          pattern length in bytes [1-8, usually 2 for screen images]
  434. 1 word          pixel width in microns (1/1000 mm, 25400 microns per inch)
  435. 1 word          pixel height in microns
  436. 1 word          line width in pixels
  437. 1 word          number of lines
  438. -------
  439. ? words         header length defined in 2nd word of header
  440.  
  441. ? bytes         data
  442.  
  443. NOTES:  If the image is a color image (planes > 1), the planes are stored
  444. separately starting with plane 0.  There is, however, no standard way of
  445. storing the color palette.  Some programs may save the palette in separate
  446. files, some may extend the header.  For this reason, you should never
  447. assume the header is 8 words long, always get the header length from the
  448. 2nd word of the header.  Also, the line width in the 7th word is the number
  449. of pixels in a line.  Since the data is encoded in byte-wide packets, the
  450. actual unpacked line width is always a multiple of 8, and may be 1-7 pixels
  451. longer than the length specified in the header.
  452.  
  453. For each byte x in the data section,
  454.  
  455.         x = 0           Pattern/scanline run.
  456.                         Read the next byte, n (unsigned).
  457.  
  458.                         If n > 0 then:
  459.                                 Read a number of bytes equal to the "pattern
  460.                                 length" word in the header.  Repeat this
  461.                                 pattern n times.
  462.  
  463.                         If n = 0 then:
  464.                                 Scanline run.  Data for the next scanline
  465.                                 is to be used multiple times.  Read the
  466.                                 following record:
  467.  
  468.                                 1 byte          flag byte [$FF]
  469.                                 1 byte          number of times to use
  470.                                                 next scanline data
  471.  
  472.                                 The data for the next scanline follows,
  473.  
  474.  
  475.         x = 80 (hex)    Uncompressed bit string.  The next byte
  476.                         determines the number of bytes to use
  477.                         literally.  The literal data bytes follow.
  478.  
  479.         otherwise       Solid run.  The value of x determines
  480.                         what to draw.  The high bit specifies whether
  481.                         the pixels are set or cleared.  A 1 indicates
  482.                         a byte-run using $FF, a 0 indicates a byte-run
  483.                         using $00.  The low 7 bits, taken as an unsigned
  484.                         quantity, specify the length of the run in bytes.
  485.  
  486.  
  487. <STAD>          *.PAC (high resolution only)
  488.  
  489. 4 bytes         "pM86" (vertically packed) or "pM85" (horizontally packed)
  490. 1 byte          id byte
  491. 1 byte          pack byte (most frequently occuring byte in bitmap)
  492. 1 byte          "special" byte
  493. -------
  494. 7 bytes         total for header
  495.  
  496. bytes         data
  497.  
  498. The data is encoded as follows.  For each byte x in the data section:
  499.  
  500.         x = id byte             Read one more byte, n.  Use pack byte 
  501.                                 n + 1 times.
  502.         x = "special" byte      Read two more bytes, d, and n (in order).
  503.                                 Use byte d n times.
  504.         otherwise               Use byte x literally.
  505.  
  506.  
  507. <Imagic Film/Picture>           *.IC1 (low resolution)
  508.                                 *.IC2 (medium resolution)
  509.                                 *.IC3 (high resolution)
  510.  
  511. 4 bytes         "IMDC"
  512. 1 word          resolution (0 = low res, 1 = medium res, 2 = high res)
  513. 16 words        palette
  514. 1 word          date (GEMDOS format)
  515. 1 word          time (GEMDOS format)
  516. 8 bytes         name of base picture file (for delta compression), or zeroes
  517. 1 word          length of data (?)
  518. 1 long          registration number
  519. 8 bytes         reserved
  520. 1 byte          compressed? (0 = no, 1 = yes)
  521.  
  522. If compressed {
  523. 1 byte          delta-compressed? (-1 = no, > -1 = yes)
  524. 1 byte          ?
  525. 1 byte          escape byte
  526. }
  527. -------
  528. 65 bytes        total for header (68 bytes if compressed)
  529.  
  530. ? bytes         data
  531.  
  532.    Compressed data may be either stand-alone or delta-compressed (relative
  533. to the base picture named in the header).  Delta compression involves
  534. storing only how the picture differs from the base picture (i.e., only
  535. portions of the screen that have changed are stored).  This is used to
  536. to encode animated sequences efficiently.
  537.  
  538. Compressed data, stand-alone:
  539.  
  540. For each byte x in the data section:
  541.  
  542.         x = escape byte         Read one more byte, n.  (n is unsigned).
  543.  
  544.                                 If n >= 2, use the next byte n times.
  545.                                 If n = 1, keep reading bytes until a
  546.                                 byte k not equal to 1 is encountered.
  547.                                 Then read the next byte d.
  548.                                 If the number of 1 bytes encountered is o,
  549.                                 use d (256 * o + k) times.  I.e.,
  550.  
  551.                                 if (n == 1) {
  552.                                         o = 0;
  553.                                         while (n == 1) {
  554.                                                 o++;
  555.                                                 n = next byte;
  556.                                         }
  557.  
  558.                                         k = n;
  559.                                         d = next byte;
  560.  
  561.                                         Use d (256 * o + k) times.
  562.                                 }
  563.                                 else {
  564.                                         d = next byte;
  565.                                         Use d (n) times.
  566.                                 }
  567.  
  568.         x != escape byte        Use x literally.
  569.  
  570. Compressed data, delta compressed:
  571.  
  572. For each byte x in the data section:
  573.  
  574.         x = escape byte         Read one more byte, n.  (n is unsigned).
  575.  
  576.                                 If n >= 3, use the next byte n times.
  577.                                 If n = 1, do the same as for n = 1 in
  578.                                 stand-alone compression (above).
  579.                                 If n = 2, then set n = next byte.
  580.                                         If n = 0, end of picture.
  581.                                         If n >= 2, take n bytes from base
  582.                                         picture.
  583.                                         If n = 1, do the same as for n = 1
  584.                                         in stand-alone compression (above),
  585.                                         but take (256 * o + k) bytes from 
  586.                                         base picture.
  587.  
  588.         x != escape byte        Use x literally.
  589.  
  590.  
  591. <IFF Format>    *.IFF
  592.  
  593. 4 bytes         "FORM" (FORM chunk ID)
  594. 1 long          length of file that follows
  595. 4 bytes         "ILBM" (InterLeaved BitMap file ID)
  596.  
  597. 4 bytes         "BMHD" (BitMap HeaDer chunk ID)
  598. 1 long          length of chunk [20]
  599. 20 bytes        1 word = image width in pixels
  600.                 1 word = image height in lines
  601.                 1 word = image x-offset [usually 0]
  602.                 1 word = image y-offset [usually 0]
  603.                 1 byte = # bitplanes
  604.                 1 byte = mask (0=no, 1=impl., 2=transparent, 3=lasso)
  605.                 1 byte = compressed [1] or uncompressed [0]
  606.                 1 byte = unused [0]
  607.                 1 word = transparent color (for mask=2)
  608.                 1 byte = x-aspect [5=640x200, 10=320x200/640x400, 20=320x400]
  609.                 1 byte = y-aspect [11]
  610.                 1 word = page width (usually the same as image width)
  611.                 1 word = page height (usually the same as image height)
  612.  
  613. 4 bytes         "CMAP" (ColorMAP chunk ID)
  614. 1 long          length of chunk [3*n where n is the # colors]
  615. 3n bytes        3 bytes per RGB color.  Each color value is a byte
  616.                 and the actual color value is left-justified in the
  617.                 byte such that the most significant bit of the value
  618.                 is the MSB of the byte.  (ie. a color value of 15 ($0F)
  619.                 is stored as $F0)  The bytes are stored in R,G,B order.
  620.  
  621. 4 bytes         "CRNG" (Color RaNGe chunk ID)
  622. 1 long          length of chunk [8]
  623. 8 bytes         1 word = reserved [0]
  624.                 1 word = animation speed (16384 = 60 steps per second)
  625.                 1 word = active [1] or inactive [0]
  626.                 1 byte = left/lower color animation limit
  627.                 1 byte = right/upper color animation limit
  628.  
  629. 4 bytes         "CAMG" (Commodore AMiGa viewport mode chunk ID)
  630. 1 long          length of chunk [4]
  631. 1 long          viewport mode bits (bit 11 = HAM, bit 3 = interlaced)
  632.  
  633. 4 bytes         "BODY" (BODY chunk ID)
  634. 1 long          length of chunk [# bytes of image data that follow]
  635. ? bytes         actual image data
  636.  
  637. NOTES: Some of these chunks may not be present in every IFF file, and may
  638. not be in this order.  You should always look for the ID bytes to find a
  639. certain chunk.  All chunk IDs are followed by a long value that tells the
  640. size of the chunk.  This is the number of bytes that FOLLOW the 4 ID bytes
  641. and size longword.  The exception to this is the FORM chunk.  The size
  642. longword that follows the FORM ID is the size of the remainder of the file.
  643. The FORM chunk must always be the first chunk in an IFF file.
  644.  
  645. The R,G,B ranges of AMIGA and ST are different (AMIGA 0...15, ST 0...7),
  646. as is the maximum number of bitplanes (AMIGA: 5, ST: 4).
  647.  
  648. Format of body data
  649.  
  650. An expanded picture is simply a bitmap.  The packing method is PackBits
  651. (see below), and is identical to MacPaint and DEGAS Elite compressed.
  652.  
  653. The (decompressed) body data appears in the following order:
  654.  
  655.         line 1 plane 0 ... line 1 plane 1 ... ... line 1 plane m
  656.         [line 1 mask (if appropriate)]
  657.         line 2 plane 0 ... line 2 plane 1 ... ... line 2 plane m
  658.         [line 2 mask (if appropriate)]
  659.         ...
  660.         line x plane 0 ... line x plane 1 ... ... line x plane m
  661.         [line x mask (if appropriate)]
  662.  
  663. The FORM chunk identifies the type of data:
  664.  
  665.         "ILBM" = interleaved bit map
  666.         "8SVX" = 8-bit sample voice
  667.         "SMUS" = simple music score
  668.         "FTXT" = formatted text (Amiga)
  669.  
  670.  
  671. <MacPaint>      *.MAC
  672.  
  673. 1 long          version number [0=ignore header, 2=header valid]
  674. 38 * 8 bytes    8x8 brush/fill patterns.  Each byte is a pattern row,
  675.                 and the bytes map the pattern rows top to bottom.  The
  676.                 patterns are stored in the order they appear at the bottom
  677.                 of the MacPaint screen top to bottom, left to right.
  678. 204 bytes       unused
  679. -------------
  680. 512 bytes       total for header
  681.  
  682. < 51200 bytes   compressed bitmap data
  683. -------------
  684. < 51712 bytes   total
  685.  
  686. NOTE:  The version number is actually a flag to MacPaint to indicate if
  687. the brush/fill patterns are present in the file.  If the version is 0,
  688. the default patterns are used.  Therefore you can simply save a MacPaint
  689. file by writing a blank header (512 $00 bytes), followed by the packed
  690. image data.
  691.  
  692. Bitmap compression:
  693.  
  694.    The bitmap data is for a 576 pixel by 720 pixel monochrome image.
  695. The packing method is PackBits (see below).  There are 72 bytes per
  696. scan line.  Each bit represents one pixel; 0 = white, 1 = black.
  697.  
  698.  
  699. <PackBits Compression Algorithm>
  700.  
  701. The following packing algorithm originated on the Mac, was adopted by
  702. Electronic Arts/Commodore for use in the IFF standard, and then by Tom
  703. Hudson for use in DEGAS Elite.  The algorithm is currently used in
  704. MacPaint, IFF, and DEGAS Elite compressed file formats.  Each scan line
  705. is packed separately, and packing never extends beyond a scan line.
  706.  
  707. For a given control byte 'n':
  708.     0 <= n <= 127   : use the next n + 1 bytes literally (no repetition).
  709.  -127 <= n <= -1    : use the next byte -n + 1 times.
  710.          n = -128   : no operation, not used.
  711.  
  712. -------------------------------------------------------------------------
  713.  
  714. * Roland Waldi contributed extensive information on the following formats:
  715.  
  716.         GEM, IMG, Doodle, STAD, Imagic Film/Picture, Art Director, IFF
  717.  
  718. ** John Brochu, ST picture formats guru, provided sage advice and many
  719.    corrections to the following formats:
  720.  
  721.         NeoChrome, DEGAS Elite Compressed, Spectrum 512 Compressed,
  722.         GEM Bit Image, IFF, MacPaint
  723.  
  724. Version of Wed May 16 18:02:25 EDT 1990
  725.